package com.glenet.salary.dao;

import java.util.ArrayList;
import java.util.List;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSession;

import com.glenet.salary.entities.HrSubTemplate;
import com.glenet.salary.util.SessionFactoryUtil;


public class HrSubTemplateDao extends HrDaoSuport {
	
	public boolean save(HrSubTemplate subTemplate){
		boolean flag = false;
		try {
			SqlSession session = SessionFactoryUtil.openSession();
			flag = session.insert("HrSubTemplate.save", subTemplate) > 0 ? true : false;
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
	
	@SuppressWarnings("unchecked")
	public List<HrSubTemplate> list(int offset, int limit){
		List<HrSubTemplate> list = new ArrayList<HrSubTemplate>();
		try {
			SqlSession session = SessionFactoryUtil.openSession();
			list = (List<HrSubTemplate>)session.selectList("HrSubTemplate.list", null, new RowBounds(offset, limit));
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	public HrSubTemplate getSubTpl(Long tplId){
		HrSubTemplate subTemplate = null;
		try {
			SqlSession session = SessionFactoryUtil.openSession();
			subTemplate = (HrSubTemplate)session.selectOne("HrSubTemplate.getSubTpl", tplId);
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return subTemplate;
	}
}
